<?php

namespace app\admin\model;

use think\Model;

class Student extends Model
{
    // 连接数据库名称
    //protected $connection = 'db2';
    // 表名
    protected $name = 'student';
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';
    // 定义时间戳字段名
    protected $createTime = 'created_at';
    protected $updateTime = false;

    public static $genderList = [
        '1' => '男',
        '2' => '女',
    ];

    public static $statusList = [
        '1' => '在校',
    ];

    public function creator()
    {
        return $this->belongsTo('Admin', 'creator_id', 'id', [], 'LEFT')->field('id,nickname');
    }

    public function bed()
    {
        return $this->hasOne('DormitoryDormBed');
    }

    public function getGenderTextAttr($value, $data)
    {
        return isset(static::$genderList[$data['gender']]) ? static::$genderList[$data['gender']] : '';
    }

    /*public function classes()
    {
        return $this->belongsTo('app\common\model\Classes');
    }*/
}
